using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxPro;

using CMS.Core.DataInterfaces;
using CMS.Data;
using CMS.Core.Domain;
using CMS.Presenters.Presenters;
using CMS.Presenters.Views;
using CMS.Data.Common;
using CMS.Web;

namespace CMS.Web.ListManager
{
    public partial class AddVBGQ : BaseUserControl, IAddVBGQView
    {
        private AddVBGQPresenter presenter;

        public AddVBGQ()
        {
            this.presenter = new AddVBGQPresenter(this, NHibernateDaoFactory.Instance.GetVBGQDao());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // For Ajax
            this.RaiseClientEvent();
            
            this.btnOK.Attributes.Add("onclick", "return CheckInput(0);");
            this.btnOKC.Attributes.Add("onclick", "return CheckInput(1);");
            this.chkTrangThai.Checked = true;
        }

        // For Ajax to validdate
        protected void RaiseClientEvent()
        {
            Utility.RegisterTypeForAjax(typeof(CMS.Presenters.Presenters.AddVBGQPresenter));
        }

        public string Message
        {
            set { //lblMessage.Text = value; 
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {   
            presenter.AddObj(Page.IsValid);
            string strFolderPath = "vbgq";
            string strFile = CMS.Web.Files.Instance.UpLoadFile(this.txtFileUpload.PostedFile, strFolderPath);
            this.btnCancel_Click(this, null);
        }

        protected void btnOKC_Click(object sender, EventArgs e)
        {
            string strFolderPath = "vbgq";
            string strFile = CMS.Web.Files.Instance.UpLoadFile(this.txtFileUpload.PostedFile, strFolderPath);           
            presenter.AddObj(Page.IsValid);            
            this.txtTrichDan.Text = "";            
            this.chkTrangThai.Checked = false; 
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(BaseUrl + "&action=VIEW");
        }

        #region IAddVBGQView Members


        public VBGQ VBGQToAdd
        {
            get 
            {
                VBGQ obj = new VBGQ();      
                obj.TrichDan = this.txtTrichDan.Text.Trim();
                obj.TenFileDinhKem = CMS.Web.Files.Instance.StandardName("vbgq", this.txtFileUpload.PostedFile);               
                obj.TrangThai = this.chkTrangThai.Checked;
                return obj;
            }
        }

        #endregion
    }
}